import { Engine } from "../engine";  
import { TextBubble, BubbleOptions } from "./text-bubble";  
import { Vector2 } from "../vector";  
  
export class BubbleManager {  
  private bubbles: TextBubble[] = [];  
  
  constructor(private engine: Engine) {}  
  
  showBubble(  
    text: string,  
    duration: number = 3000,  
    options: Partial<BubbleOptions> = {}  
  ): TextBubble {  
    // 清除现有气泡  
    this.clearBubbles();  
  
    const bubble = new TextBubble(this.engine, text, duration, options);  
    bubble.show();  
    this.bubbles.push(bubble);  
    return bubble;  
  }  
  
  clearBubbles(): void {  
    this.bubbles.forEach(bubble => bubble.hide());  
    this.bubbles = [];  
  }  
  
  update(): void {  
    // 移除已过期的气泡  
    this.bubbles = this.bubbles.filter(bubble => bubble.isVisible);  
  }  
  
  render(ctx: CanvasRenderingContext2D): void {  
    if (!this.engine.player || this.engine.player.isDead) return;  
  
    const playerPos = this.engine.player.body_.pos;  
      
    for (const bubble of this.bubbles) {  
      bubble.render(ctx, playerPos);  
    }  
  }  
}